package com.woniu.springbootrbac.security;

import com.woniu.springbootrbac.entity.SysUser;
import com.woniu.springbootrbac.service.PerService;
import com.woniu.springbootrbac.service.UserService;
import com.woniu.springbootrbac.vo.PerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.List;

public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserService userService;
    @Autowired
    private PerService perService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = userService.selectByTel(username);
        List<PerVo> perVos = perService.selectMenuByTel(username, 0);
        LoginUser loginUser = new LoginUser();
        loginUser.setUser(sysUser);
        loginUser.setMenuList(perVos);
        return loginUser;
    }
}
